import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.Test;

/**
 * admin
 *
 * @author admin
 * @date 2019-10-21 9:37
 */
public class ProxyJsoup {
    @Test
    public void methodTest() throws Exception {
        Document doc = Jsoup.connect("https://www.sina.com")
                .proxy("120.79.66.7", 8188)
                .header("Accept", "*/*")
                .header("Accept-Encoding", "gzip, deflate")
                .header("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
                //.header("Referer", "https://www.baidu.com/")
                .header("Referer", "https://www.sina.com")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0")
                .timeout(5000)
                .post();
        System.out.println("doc = " + doc);
    }

    @Test
    public void methodTest2() throws Exception {
        String s = Jsoup.connect("https://www.sina.com")
                //.proxy("111.9.92.192", 1080)
                .proxy("211.152.33.24", 59523)
                .header("Accept", "*/*")
                .header("Accept-Encoding", "gzip, deflate")
                .header("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
                .header("Referer", "https://www.sina.com/")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0")
                .timeout(5000)
                .get().text();
        System.out.println("s = " + s);
    }
}
